#ifndef AD7190_H_
#define AD7190_H_

#include "stm32f4xx_hal.h"

/**
 * @errorCode
 * @{
 */
#define HAL_AD7190_ERROR_NONE       0U
#define HAL_AD7190_ERROR_WRITE      1U
#define HAL_AD7190_ERROR_READ       2U
#define HAL_AD7190_ERROR_CONFIG     3U
#define HAL_AD7190_ERROR_MODE       4U
#define HAL_AD7190_ERROR_TIMEOUT    5U
#define HAL_AD7190_ERROR_HARDWARE   6U
/**
 * @}
 */

/**
 * @config
 * @{
 */
#define AD7190_AIN1_AIN2           0x01
#define AD7190_AIN3_AIN4           0x02
#define AD7190_GAIN_1              0x0     //输入正负5V
#define AD7190_GAIN_8              0x3     //输入正负625mV
#define AD7190_GAIN_16             0x4     //输入正负312.5mV
#define AD7190_GAIN_32             0x5     //输入正负156.2mV
#define AD7190_GAIN_64             0x6     //输入正负78.125mV
#define AD7190_GAIN_128            0x7     //输入正负39.06mV
#define AD7190_BIPOLARITY          0x0     //双极性
#define AD7190_UNPOLARITY          0x1     //单极性
#define AD7190_OUTPUTRATE_50HZ     0x060
/**
 * @}
 */

/**
 * @state
 * @{
 */
typedef enum
{
  HAL_AD7190_STATE_RESET      = 0x00U,
  HAL_AD7190_STATE_READY      = 0x01U,
  HAL_AD7190_STATE_BUSY       = 0x02U,
  HAL_AD7190_STATE_ERROR      = 0x06U 
}HAL_AD7190_StateTypeDef;
/**
 * @}
 */

/**
 * @struct
 * @{
 */
typedef struct
{
    uint32_t Channel;
    uint32_t Gain;
    uint32_t Polarity;
    uint32_t OutputRate;
} AD7190_InitTypeDef;

typedef struct {
    AD7190_InitTypeDef init;
    SPI_HandleTypeDef *SPI_Handle;
    HAL_LockTypeDef Lock;
    __IO HAL_AD7190_StateTypeDef State; 
    __IO uint32_t ErrorCode;
} AD7190_HandleTypeDef;
/**
 * @}
 */

/**
 * @api
 * @{
 */
HAL_StatusTypeDef HAL_AD7190_Init(AD7190_HandleTypeDef *had7190);
HAL_StatusTypeDef HAL_AD7190_Deinit(AD7190_HandleTypeDef *had7190);
uint32_t HAL_AD7190_Step(AD7190_HandleTypeDef *had7190, uint32_t timeout);
/**
 * @}
 */

#endif /* AD7190_H_ */
